home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
TCL1
/
GRAPH_FO
/
(GRAPH
/
GRAPH_SO
/
GREDGE.C
< prev
next >
Wrap
Text File
|
1991-06-13
|
5KB
|
234 lines
/******************************************************************************
GrEdge.c
Graph methods in Object C.
This implements the GrEdge class.
SUPERCLASS = GrNode
Copyright ⌐ 1991 Maarten Meijer. All rights reserved.
CIS 100016,1764; FidoNet 2:512/114
*******************************************************************************/
#include "GrEdge.h"
#include <Global.h>
#define DELTA 2 /* size of edge hotRegion */
#define INOUT /* separate input from output edges */
/* #define DEBUGEDGE /* draw edge hotRegion outlines */
#define SELFRECT 20
/* GrEdge methods ****************************************************/
void
GrEdge::IGraphNode() {
inherited::IGraphNode();
fromVertex = toVertex = (GrVertex *)NULL;
}
void
GrEdge::_Draw() {
Point whereFrom, whereTo;
Rect r, fromRect, toRect;
if((fromVertex != (GrVertex *)NULL) && (toVertex != (GrVertex *)NULL)) {
if(fromVertex == toVertex) {
whereFrom = fromVertex->center;
r.top = whereFrom.v;
r.left = whereFrom.h;
r.bottom = whereFrom.v + SELFRECT;
r.right = whereFrom.h + SELFRECT;
FrameOval(&r);
}
else {
whereFrom = fromVertex->center;
whereTo = toVertex->center;
#ifdef INOUT
fromVertex->GetRect(&fromRect);
toVertex->GetRect(&toRect);
MoveTo(fromRect.right, whereFrom.v);
LineTo(fromRect.right + 5, whereFrom.v);
LineTo(toRect.left - 5, whereTo.v);
LineTo(toRect.left, whereTo.v);
#else
MoveTo(whereFrom.h, whereFrom.v);
LineTo(whereTo.h, whereTo.v);
#endif
}
}
}
void
GrEdge::Draw() {
_Draw();
/* this is now handled by the Draw(&area) method */
/*
#ifndef INOUT
fromVertex->Draw();
toVertex->Draw();
#endif
*/
}
void
GrEdge::_Erase() {
/*
PenState ps;
GetPenState(&ps);
PenPat(white);
_Draw();
SetPenState(&ps);
#ifdef DEBUGEDGE
if(hotRegion)
EraseRgn(hotRegion);
#endif
*/
}
void
GrEdge::Erase() {
/*
_Erase();
fromVertex->Draw();
toVertex->Draw();
*/
}
void
GrEdge::SetRegion() {
register Point to, from;
register int dh;
Point temp;
Rect toRect, fromRect;
to = toVertex->center;
from = fromVertex->center;
if( EqualPt(to, from) ) {
inherited::SetRegion();
OpenRgn();
_Draw();
CloseRgn(hotRegion);
}
else {
#ifdef INOUT
fromVertex->GetRect(&fromRect);
toVertex->GetRect(&toRect);
to.h = toRect.left - 5;
from.h = fromRect.right + 5;
#endif
temp.h = from.h - to.h;
temp.v = from.v - to.v;
if((temp.h > 0 && temp.v > 0) || (temp.h < 0 && temp.v < 0)) {
dh = -(DELTA);
}
else {
dh = DELTA;
}
inherited::SetRegion();
OpenRgn();
MoveTo(from.h + dh, from.v + DELTA);
LineTo(to.h + dh, to.v + DELTA);
LineTo(to.h - dh, to.v - DELTA);
LineTo(from.h - dh, from.v - DELTA);
LineTo(from.h + dh, from.v + DELTA);
CloseRgn(hotRegion);
#ifdef DEBUGEDGE
if(hotRegion != NULL)
FrameRgn(hotRegion);
#endif
}
}
Boolean
GrEdge::Incident(GrNode *which) {
return((fromVertex == which) || (toVertex == which));
}
void
GrEdge::SetFrom(GrVertex *which) {
if((fromVertex != (GrVertex *)NULL) && (toVertex != (GrVertex *)NULL)) {
Erase();
}
fromVertex = which;
if((fromVertex != (GrVertex *)NULL) && (toVertex != (GrVertex *)NULL)) {
Draw();
SetRegion();
}
}
GrVertex *
GrEdge::GetFrom() {
return fromVertex;
}
void
GrEdge::SetTo(GrVertex *which) {
if((fromVertex != (GrVertex *)NULL) && (toVertex != (GrVertex *)NULL)) {
Erase();
/* toVertex->Draw(); */ /* allready in Erase() */
}
toVertex = which;
if((fromVertex != (GrVertex *)NULL) && (toVertex != (GrVertex *)NULL)) {
Draw();
/* fromVertex->Draw(); */
/* toVertex->Draw(); */
SetRegion();
}
}
GrVertex *
GrEdge::GetTo() {
return toVertex;
}
/******************************************************************************
GetRect
return the rect that encloses this edge's fromVertex & toVertex
*******************************************************************************/
void
GrEdge::GetRect(register Rect *rect) {
Point pt1, pt2;
Rect fromRect, toRect;
pt1 = fromVertex->GetCenter();
pt2 = toVertex->GetCenter();
if( EqualPt(pt1, pt2) ) { /* self ref */
pt2.h += SELFRECT;
pt2.v += SELFRECT;
Pt2Rect(pt1, pt2, rect);
}
else
{
Pt2Rect(pt1, pt2, rect);
if(rect->top == rect->bottom)
InsetRect(rect, 0, -5);
if( rect->left == rect->right || pt1.h >= pt2.h) {
fromVertex->GetRect(&fromRect);
toVertex->GetRect(&toRect);
UnionRect(&fromRect, &toRect, rect);
InsetRect(rect, -15, 0);
}
rect->bottom += 1;
rect->right += 1;
}
}
/******************************************************************************
NodeInRect
Determine if the edge is within a specified Rect, to see whether
needs to be redrawn. Should this methode use SectRect??
*******************************************************************************/
Boolean
GrEdge::NodeInRect(Rect *r) {
Rect area;
GetRect(&area);
return SectRect(r, &area, &area);
/* return RectInRgn(r, hotRegion);*/
}